from page.net_project_page import NetProjectPage
from common.page import IOS, XPATH
import time as t


class NetQuestionPage(NetProjectPage):

    # 列表页
    not_submit = (IOS, "type == 'XCUIElementTypeStaticText' AND label == '未提交'")

    # 详情页
    question_info = (IOS, "type == 'XCUIElementTypeButton' AND label == '查看详情'")
    blank_btn = (IOS, "type == 'XCUIElementTypeButton' AND label == '立即作答'")
    back = (IOS,"type == 'XCUIElementTypeButton' AND label == 'top返回'")

    # 答题页面
    answer_A = (IOS, "type == 'XCUIElementTypeButton' AND label == 'A'")
    answer_B = (IOS, "type == 'XCUIElementTypeButton' AND label == 'B'")
    confirm_answer = (IOS, "type == 'XCUIElementTypeButton' AND label == '确认'")  # 多选题、填空题、问答题确认答案
    area_test = (XPATH, "//XCUIElementTypeStaticText[@name='答']/../XCUIElementTypeTextView")

    submit_answer = (IOS, "type == 'XCUIElementTypeButton' AND label == '提交'")

    def submit_question(self):    #苹果6
        # 进入问卷
        self.find_element(*self.not_submit).click()
        self.find_element(*self.question_info).click()
        t.sleep(2)
        self.find_button(string="返回按钮", contains_flag=1).click()

        # 判断
        self.find_element(*self.blank_btn).click()
        self.find_element(*self.answer_A).click()
        t.sleep(1)
        # 单选
        self.find_element(*self.answer_B).click()
        t.sleep(1)
        # 多选
        self.find_element(*self.answer_A).click()
        self.find_element(*self.answer_B).click()
        # self.find_element(*self.confirm_answer).click()
        self.find_button('确定').click()
        # 填空
        self.find_element(XPATH,
                          "//XCUIElementTypeButton[@name='A']/../XCUIElementTypeTextField").send_keys("这是A的答案。不敢保证全部都是正确的，自己理解的而已。")
        self.find_element(XPATH,
                          "//XCUIElementTypeButton[@name='B']/../XCUIElementTypeTextField").send_keys("这是B的答案。不敢保证全部都是正确的，自己理解的而已。")
        # self.find_element(*self.confirm_answer).click()
        self.find_button('确定').click()
        # 问答
        self.find_element(*self.area_test).send_keys("这是问答题答案问题答案，请大家详细查看问题出在哪一块，好整理好自己的笔记、、、")
        # self.find_element(*self.confirm_answer).click()
        self.find_button('确定').click()
        self.find_element(*self.submit_answer).click()
        t.sleep(1)
        self.swipe(17,23,17,23)
        self.swipe(22, 32, 22, 32)
        # self.find_button(string="返回" , contains_flag=1).click()
        # self.find_button(string="返回", contains_flag=1).click()

    def submit_questions(self):    #苹果6s
        # 进入问卷
        # self.find_element(*self.not_submit).click()
        self.find_static_text(string="未提交",contains_flag=1).click()
        self.find_element(*self.question_info).click()
        t.sleep(2)
        self.find_element(*self.back).click()
        # self.find_button(string="返回按钮", contains_flag=1).click()
        # 判断
        t.sleep(2)
        self.find_element(*self.blank_btn).click()
        self.find_element(*self.answer_A).click()
        t.sleep(1)
        # 单选
        self.find_element(*self.answer_B).click()
        t.sleep(1)
        # 多选
        self.find_element(*self.answer_A).click()
        self.find_element(*self.answer_B).click()
        # self.find_element(*self.confirm_answer).click()
        self.find_button('确定').click()
        # 填空
        self.find_element(XPATH,
                          "//XCUIElementTypeButton[@name='A']/../XCUIElementTypeTextField").send_keys("这是A的答案。是根据我自己的理解进行回答的，不敢保证一定是正确的。")
        self.find_element(XPATH,
                          "//XCUIElementTypeButton[@name='B']/../XCUIElementTypeTextField").send_keys("这是B的答案。是根据我自己的理解进行回答的，不敢保证一定是正确的。")
        # self.find_element(*self.confirm_answer).click()
        self.find_button('确定').click()
        # 问答
        self.find_element(*self.area_test).send_keys("这是问答题答案相反，那种不知敬畏的人是从不在人格上反省自己的。如果说�知耻近乎勇�，那么，这种人因为不知耻便显出一种卑怯的放肆。只要不受惩罚，他敢于践踏任何美好的东西，包括爱情、友谊、荣誉，而且内心没有丝毫不安。这样的人尽管有再多的艳遇，也没有能力真正爱一回；结交再多的哥们，也体味不了友谊的纯正；获取再多的名声，也不知什么是光荣。不相信神圣 的人，必被世上一切神圣的事物所抛弃。")
        # self.find_element(*self.confirm_answer).click()
        self.find_button('确定').click()
        self.find_element(*self.submit_answer).click()
        t.sleep(1)
        self.swipe(22,23,22,23)
        t.sleep(0.5)
        # self.swipe(22,32,22,32)
        self.find_button(string="common back light icon", contains_flag=1).click()

    def Request(self):
        self.find_button("去填写").click()




if __name__ == '__main__':
    test = NetQuestionPage()
    test.enter_project()
    test.enter_tools("调查问卷")
    # test.submit_question()    #6
    test.submit_questions()   #6s
